home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
-
- #define NTIMES 10 /* number of times to compute Fibonacci value */
- #define NUMBER 24 /* biggest one we can compute with 16 bits */
-
-
- main() /* compute Fibonacci value */
- {
- int i;
- unsigned value, fib();
-
- printf("%d iterations: ", NTIMES);
-
- for (i = 1; i <= NTIMES; i++)
- value = fib(NUMBER);
-
- printf("Fibonacci(%d) = %u.\n", NUMBER, value);
- exit(0);
- }
-
-
- unsigned fib(x) /* compute Fibonacci number recursively */
- int x;
- {
- if (x > 2)
- return (fib(x - 1) + fib(x - 2));
- else
- return (1);
- }